home *** CD-ROM | disk | FTP | other *** search
/ Inside Mac Games Volume 4 #1 & #2 / IMG 34 JanFeb 1996.iso / IMG Jan⁄Feb 1996 / IMG Jan_Feb 1996.rsrc / TEXT_143.txt < prev    next >
Text File  |  1996-02-19  |  16KB  |  290 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17. by Jamie McCornack
  18.  
  19.  
  20. But before we get started, I must confess a bug in my text. So for you Loyal Readers who‚Äôve been following this column for a few months‚Ķ
  21.  
  22. Synchronous? Asynchronous? My dog ate my homework?
  23. In the November column (Some Sound Advice)‚Ķwell, I lied. The three paragraphs after the header Synchronous vs. Asynchronous Sound are exactly backward. It‚Äôs correct in the book (page 32, Tricks of the Mac Game Programming Gurus, Hayden Books, 1995), and I wrote both the column and the book chapter I lifted it from, so I ought to know better, right? And if I know better, you‚Äôd think I‚Äôd write better.
  24. Synchronous sound is ‚Äúsynchronized‚Äù to screen action in the crudest possible way‚Äîwhen synchronous sounds are playing, all screen activities are locked up solid. This is fine if you want an immobile warning sign in the background while your Mac says, ‚ÄúIntruder alert, intruder alert,‚Äù or, ‚ÄúCoin detected in pocket,‚Äù but in the real world of game development, you‚Äôll want sound and graphic action to be independent of each other (asynchronous) instead of sequential (synchronous).
  25.  
  26. Folks get it mixed up, thinking ‚Äúsynchronous‚Äù must mean the game characters‚Äô lips are moving while the sound is playing, but that‚Äôs not the way it is in the Toolbox. To the Mac Toolbox SndPlay() function, ‚Äúsynchronous‚Äù means sound-then-action, and ‚Äúasynchronous‚Äù means action can continue while the sound is playing. 99 times out of 100, asynchronous sound is what you want. And that‚Äôs the truth.
  27.  
  28. Sorry about last month. My thanks to Alert Reader MacGregory for pointing out the error of my ways. At least I got it right in the comments to the code(MGWSound1.c, lines 375 to 425).
  29.  
  30. And now, back to this month‚Äôs column, which is already in progress‚Ķ
  31.  
  32. Clams in Combustion
  33. Though for the most part, the ambulatory clams I‚Äôve been using in these demos have been well received, one recurring question keeps finding its way to me:
  34. ‚ÄúLove your column, Jamie, and the clams are charming, but how do you go about blowing them up?‚Äù
  35.  
  36. From the programming standpoint, this is a trivial task. From the standpoint of the art department, this is an interesting challenge. Fortunately, there are resources available, or it would be a hair-pulling cola-swilling allnighter challenge, since animated fiery explosions are extraordinarily difficult to draw by hand.
  37.  
  38. ETHICS ALERT!!! THE FOLLOWING TWO PARAGRAPHS HAVE NOTHING TO DO WITH PROGRAMMING OR ART DEVELOPMENT TECHNIQUES!
  39.  
  40. I am unconcerned about this demo‚Äôs impact on society. As excellent as it might be, I doubt it will inspire anyone to skulk down to Cap‚Äôn Jack‚Äôs Seafood Emporium and commit a copycat crime. Yes, blowing things up is a staple of the computer game genre, and yes, if you‚Äôre going to do it, you should do it well. Still, to quote john calhoun, nobody ever lost sleep from writing a nonviolent game. The techniques herein can be used in appropriate or inappropriate context. Are you blowing up asteroids before they can plunge into the atmosphere and smoosh all creatures here below? Neato! Are you incinerating University of Alabama cheerleaders? Then even if you‚Äôre an Auburn fan, I‚Äôd suggest you ask your shrink to lighten up a bit on your medication, okay?
  41.  
  42. Even these clams‚Ķlook, there‚Äôs no such thing as a clam with legs, certainly not with legs in orange trousers, and if it wasn‚Äôt for the beach scene, most folks wouldn‚Äôt even recognize it as a representation of a clam. Yet when I showed the finished GoodbyeWorld program to one of my partners, she said, ‚ÄúAwwww,‚Äù and didn‚Äôt think it was funny at all. So imagine we‚Äôre developing the game of Help Claudia Clam Find Her Pearl, Ages 3-6, and quicker than the player can say, ‚ÄúWhat does ‚ÄòBeware of Minefield‚Äô mean, Daddy?‚Äù Claudia goes off like a drummer for Spinal Tap. Think a bit about the impression you‚Äôre making. Okay, back to the column.
  43.  
  44. So the project manager says, ‚ÄúCan it be done?‚Äù and the lead programmer says, ‚ÄúPiece of cake, we‚Äôll have the clambake code done by the end of the day. Have the art department whip up a PICT sequence for an exploding fireball, oh, eight frames long, 64 by 64 pixels, 256 colors, standard system pallet.‚Äù
  45.  
  46. So the project manager passes the request on to the art department, finishing with, ‚Äú‚Ķand we need it by the end of the day,‚Äù and the art director has a good laugh and says, ‚ÄúYeah, right. Who is this really? You sound just like our project manager,‚Äù and says she‚Äôll see what they can do but don‚Äôt get your hopes up.
  47.  
  48. A little later she calls back and says, ‚ÄúCliff and Lisa say they can have it done by five A.M. on their Macs at home, if they get started on it right now, but they want Friday off to make up for it, you want to approve that?‚Äù and the project manager says, ‚ÄúYeah, all right, whatever it takes to get the job done.‚Äù So Cliff and Lisa leave the office and go somewhere for a leisurely lunch, and do some shopping, and go to the gym to play some racquetball and swim a few laps, and later at dinner who should walk into the restaurant but the program manager. ‚ÄúIt‚Äôs going okay, we‚Äôll have this job wrapped up before dawn, we had to eat something and there isn‚Äôt time to cook,‚Äù Cliff says wearily. ‚ÄúWe sure appreciate what you‚Äôre doing,‚Äù says the project manager, picking up the check, ‚ÄúThis one‚Äôs on the company.‚Äù Lisa doesn‚Äôt say anything. She‚Äôs trying not to laugh, because back at home, she has a copy of Pyromania!
  49.  
  50. Pyromania!  and Pyromania2 ($199.95 each, VCE Inc., 818-367-9187) are CD-ROM collections of 640 x 480 (and up) 32-bit color PICT files of various explosions, fires, fireworks, sparks, and smoke, shot against a black background by a genuine Hollywood special effects studio. Explosion sequences run from 40 to 80 frames as a rule, while fire sequences run up around 200 frames. These aren‚Äôt video captured, they are scanned from 35mm motion picture film‚Äîthey are sharp and clear and there are no strange artifacts. They look like what you see in the movies, and I don‚Äôt mean Ed Wood productions.
  51.  
  52. Explosions run the gamut of ground, air, zero G, flak, and assorted shockwave explosions. For our spontaneous clambustion demonstration, we‚Äôll use a medium size zero G fiery explosion. Here is a typical frame, of which there are over a thousand per disc, clipped slightly to fit on this page:
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. If your monitor is set to Millions of colors, this looks gorgeous, and at Thousands, it looks terrific. At 256 colors, well, it looks a bit spotty. That's one of our jobs, to optimize this explosion for 256 colors.
  70.  
  71. This frame is ZG02.127 from a series that runs from ZG02.100 to ZG02.157. In explosions, things happen pretty fast and changes are dramatic from frame to frame, but we don‚Äôt need every frame of that great big explosion to blow up a modest little clam.
  72.  
  73. Back home, Lisa asks Cliff to make a PICT with nine 64 x 64 boxes laid out in a square, while she finds her Pyromania! disc. Cliff opens Zeus (Delta Tao Software, 408-730-9336), which is his favorite paint program (despite its quirks, it has a bunch of cool features that appeal to a guy like Cliff), and whips up this grid:
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91. Note that the boxes are 64 x 64 inclusive of the lines. If the art covers a line, no problem, just erase the line. The lines are only there to guide the artists. However, the art cannot go past a line, or even into the line of the neighboring box (which is why the lines are two slightly different colors), or is will show up in the wrong sprite face when the program is run. Anyway, one of the reasons Cliff likes Zeus is because of its clear and accurate dimensioning tools, so it only takes five minutes to come up with this grid.
  92.  
  93. Lisa sticks the Pyromania! disc in the slot, and they pore over the QuickTime preview movies to find an explosion they like. Yep, ZG02 look like the cat‚Äôs pajamas, so they open its PICT folder, where thumbnails of the frames are laid out in chronological order.
  94.  
  95. ‚ÄúThe first frames are boring, and the last frames are boring,‚Äù says Cliff, ‚Äúso let‚Äôs pick the eight best frames out of the middle.‚Äù
  96.  
  97. ‚ÄúSeven frames,‚Äù says Lisa, ‚ÄúIf we skip the first six frames, and then take every seventh frame until we have seven frames, we‚Äôll be done before Blockbuster closes.‚Äù
  98. ‚ÄúWhy seven frames?‚Äù Cliff asks, ‚Äúthey said they want an eight frame sequence.‚Äù
  99. ‚ÄúBecause the last frame should be blank,‚Äù says Lisa. ‚ÄúIt‚Äôll make the programming easier if they have a frame with nothing happening, the explosion‚Äôs done with and the clam is history.‚Äù
  100.  
  101. They open ZG02.127, which looks like the biggest image, at 25% scaling and measure it. Nope, 84 pixels at the widest. Try ZG01.127. Good, 54 pixels for the main explosion, which leaves room for those bits of clam shrapnel. Create a ClaBoomΔí folder on the hard disk, save this PICT at 256 colors (art department talk for 8-bit color), name it ClaPop127 (slightly smaller than ClaBoom)‚Ķ
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114. ‚Ķand do the same with frames ZG02.106, .113, .120, .134, .141, and .148. Then they open ClaPop127 again, select white as the fill color, and use the paintbucket tool to change the background from black to white.
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123. ‚ÄúThat‚Äôs going to leave us a lot of handwork around the edges,‚Äù Cliff says, so they move the precision selector on the paintbucket tool from Exact down a little toward Vague (that‚Äôs one of the reasons Cliff likes Zeus) to get rid of some of the almost-black pixels.
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132. So they do a bit of handwork with the pencil tool, erasing a few pixels that don‚Äôt fit their artistic tastes, and copy-and-paste the seven frame sequence into the grid, saving the result as BoomSprites.
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151. ‚ÄúNow we make the mask,‚Äù says Lisa, ‚Äúand we‚Äôre done. Sure hope we‚Äôre done in time to rent a video.‚Äù
  152.  
  153. ‚ÄúPiece of cake,‚Äù says Cliff, making literary recursive history by waving this very CD-ROM in the air‚Äîthe January ‚Äô96 issue of Inside Mac Games‚Äîand saying in melodramatic tones, ‚ÄúI have here‚Ķthe Mask of Zorro!‚Äù
  154.  
  155. Sure enough, ZorroTable is here in the code folder for this month‚Äôs column. It is a Photoshop color table with 255 black entries and one white entry. Cliff and Lisa quit Zeus and open BoomSprites in Photoshop. They go to the Mode menu, select Color Table‚Ķ, load ZorroTable, and wallah!
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173. ‚ÄúWhy are the first three frames all speckled?‚Äù Lisa asks.
  174.  
  175. ‚ÄúBecause there was a lot of white in the early stages of the explosion. We can fill them in with the brush or pencil, it‚Äôll just take a jiffy. And we have to erase the grid lines, but if we erase them by hand where they touch the artwork‚Ķ
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194. ‚Äú‚Ķwe can get rid of the grid with the paintbucket. Then we go back to Mode and select Bitmap, 50% Threshold and save it as BoomMask. There, easier done than said.‚Äù
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211. ‚ÄúAnd we‚Äôre outta here,‚Äù says Cliff, grabbing his hat.
  212.  
  213. ‚ÄúUh, let‚Äôs think about this for a minute,‚Äù says Lisa. ‚ÄúWe‚Äôve made an explosion sprite set in record time, and it‚Äôs right to project specs, but we‚Äôre talented and creative artists, right? I mean, that‚Äôs why they pay us the big bucks‚Ķ
  214.  
  215. [pause for laughter here, and wait for those with computer graphics careers to catch their breath]
  216.  
  217. ‚Äú‚Ķand this is not as good as we can make it. Even though we‚Äôve dumbed it down to 256 colors and seven frames, this explosion still borders on the photorealistic. The clams, on the other hand, are cartoons. It‚Äôs not going to look right. You know how Wile E. Coyote is always getting run over by trucks in the Road Runner cartoons? Well what if after the truck went by, they switched to a photograph of what a coyote really looks like after a truck has run over it and‚Ķ‚Äù
  218.  
  219. ‚ÄúYeah, I hear you, you‚Äôre right,‚Äù says Cliff, ‚Äúbut we can still be out of here in ten minutes, because I have another of Jamie‚Äôs cluts here‚Ķ‚Äù
  220.  
  221. ‚ÄúWho‚Äôs this Jamie you‚Äôre talking about?‚Äù asks Lisa.
  222.  
  223. ‚ÄúBrilliant, brilliant man,‚Äù says Cliff, with sincere respect in his voice. ‚ÄúAnyway, he has a clut called HotSwapTable with only 16 colors on it. There‚Äôs one black entry, 31 white entries, and 16 entries each going from bright yellow, through orange, and down to deep red. Sure, he stole the idea from Video Fusion, which has a Black Body color set you can apply to video, but there‚Äôs no denying this is an inspired application of‚Ķ‚Äù
  224. ‚ÄúFine, enough fawning, we haven‚Äôt got all night. How does it work?‚Äù Lisa asks.
  225. ‚ÄúOpen a copy of BoomSprites in Photoshop, select Color Table from the Mode menu, load HotSwapTable, and click Okay,‚Äù says Cliff.
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244. ‚ÄúHey, cool!‚Äù says Lisa. ‚ÄúNot brilliant, ‚Äôcause I see some white speckles in this one too, but definitely cool.‚Äù
  245.  
  246. Cliff shrugs. ‚ÄúYeah, some of the real dark pixels come out white. We can fix them with the eyedropper and pencil tools. Then all we have to do is convert it to the System color table.‚Äù
  247.  
  248. ‚ÄúSo go back to the Mode menu, and select System from the Color Table‚Ķ‚Äù
  249.  
  250. ‚ÄúNah,‚Äù says Cliff, ‚ÄúI tried that once, and I ended up right back where I started. First convert it to Mode RGB Color, then convert it back to Indexed Color. Choose 8-bit resolution and System Palette, and save it as CartoonBoomSprites. You end up with exaggerated fire colors, using the same color table as the clams and the beach, so there‚Äôs no color conversion lag in the animation. BoomSprites and CartoonBoomSprites use the same mask, so let‚Äôs turn them both in and let the project manager choose a favorite.‚Äù
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269. ‚ÄúAlllllrighty then,‚Äù says Lisa, ‚Äúwhat movie do you want to see?‚Äù
  270.  
  271. Meanwhile, back at the Programmer‚Äôs Pit‚Ķ
  272. If you got through the October installment of this column, the programming here will be a breeze. If you didn‚Äôt, well, it‚Äôs all available in Chapter 0 of Tricks of the Etcetera Etcetera and I hear there‚Äôs going to be an IMG Back Issue CD-ROM set available (probably mentioned elsewhere in this mag).
  273.  
  274. Open the GoodbyeWorld1.c source code file. To make the new stuff more obvious, the program has been simplified from recent HelloWorld versions; a single clam and no mood music.
  275.  
  276. We have some new constants, kBoomFace0 through kBoomFace7. Note we use the word ‚Äúface‚Äù in this context to describe a particular member of a sprite set, rather than that thing on the front of a head. The animation of the explosion is only different from the animation of the running clam in one significant way: the explosion does not move, so ShowExplosion(), unlike ShowClam(), does not require a union of the rect where it is and the rect where it‚Äôs been.
  277.  
  278. kShrinkFactor sets how much smaller the fireIsAt rect is than the clamIsAt rect, and since we want fireIsAt rect to be bigger (64 x 64) than clamIsAt rect (32 x 32), kShrinkFactor is a negative number.
  279.  
  280. Both of the explosion sprite sets are in the resource file; set rFireFacesID to 141 for the cartoon version, 142 for the photo version. Oh yes, and we‚Äôve added rExplodeSndID to our 'snd ' resources, and changed rHelloSnd to rGoodbyeSnd.
  281.  
  282. The new variables are what you‚Äôd expect; fireFacesCPort, fireMasksPort and some new rects to locate the proper faces, etc. 
  283.  
  284. Explode() is nearly identical to LipSynch(), except the sprite faces selected show an exploding fireball instead of a talking clam. Note the last face selected is blank‚Äîa lazy way to erase the final frame of the explosion. If Macs still had 128K of RAM like they did a dozen years ago, I‚Äôd do something more sophisticated.
  285.  
  286. Why are there two blank frames in the explosion art? I thought I might want to leave some smoking rubble on the beach, but we found the Cajun Style Blackened Clam to be unappetizing.
  287.  
  288. SayGoodbye() gives us an orderly transition from LipSynch() to Explode(). The one slick thing we do in SayGoodbye() is to set the rect variable fireIsAt to be equal to clamIsAt, so the explosion will happen where the clam is, and then expand fireIsAt from a 32 x 32 pixel rect to a 64 x 64 pixel rect via the Toolbox routine InsetRect(). InsetRect was developed to shrink rects (such as windows when you close them), but it expands rects quite nicely when fed negative numbers. So we ‚Äúinset‚Äù by -16, which pushes each edge of the rect 16 pixels outward.
  289.  
  290. Goodbye, World! See you next month.